Public Class frmCOASearch
    Inherits System.Windows.Forms.Form
    Dim glcAdd As frmGLAccountsAdd
    Dim glcEdit As frmCOAEdit
    Friend WithEvents Label3 As System.Windows.Forms.Label
    Friend WithEvents cmbAccGroup As DevComponents.DotNetBar.Controls.ComboBoxEx
    Friend WithEvents GroupPanel1 As DevComponents.DotNetBar.Controls.GroupPanel
    Friend WithEvents cmdExit As DevComponents.DotNetBar.ButtonX
    Friend WithEvents cmdEdit As DevComponents.DotNetBar.ButtonX
    Friend WithEvents cmdRefresh As DevComponents.DotNetBar.ButtonX
    Friend WithEvents cmdPrint As DevComponents.DotNetBar.ButtonX
    Dim dsAccounts As DataSet

#Region " Windows Form Designer generated code "

    Public Sub New()
        MyBase.New()

        'This call is required by the Windows Form Designer.
        InitializeComponent()

        'Add any initialization after the InitializeComponent() call

    End Sub

    'Form overrides dispose to clean up the component list.
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.  
    'Do not modify it using the code editor.
    Friend WithEvents dgProduct As System.Windows.Forms.DataGrid
    Friend WithEvents cmbCompany As System.Windows.Forms.ComboBox
    Friend WithEvents cmbDpt As System.Windows.Forms.ComboBox
    Friend WithEvents PrintDocument1 As System.Drawing.Printing.PrintDocument
    Friend WithEvents ToolTip1 As System.Windows.Forms.ToolTip
    Friend WithEvents iPrint As GLlistOfAccounts
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.components = New System.ComponentModel.Container()
        Me.cmbDpt = New System.Windows.Forms.ComboBox()
        Me.dgProduct = New System.Windows.Forms.DataGrid()
        Me.cmbCompany = New System.Windows.Forms.ComboBox()
        Me.PrintDocument1 = New System.Drawing.Printing.PrintDocument()
        Me.ToolTip1 = New System.Windows.Forms.ToolTip(Me.components)
        Me.iPrint = New GLlistOfAccounts()
        Me.Label3 = New System.Windows.Forms.Label()
        Me.cmbAccGroup = New DevComponents.DotNetBar.Controls.ComboBoxEx()
        Me.GroupPanel1 = New DevComponents.DotNetBar.Controls.GroupPanel()
        Me.cmdPrint = New DevComponents.DotNetBar.ButtonX()
        Me.cmdRefresh = New DevComponents.DotNetBar.ButtonX()
        Me.cmdExit = New DevComponents.DotNetBar.ButtonX()
        Me.cmdEdit = New DevComponents.DotNetBar.ButtonX()
        CType(Me.dgProduct, System.ComponentModel.ISupportInitialize).BeginInit()
        Me.GroupPanel1.SuspendLayout()
        Me.SuspendLayout()
        '
        'cmbDpt
        '
        Me.cmbDpt.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList
        Me.cmbDpt.Font = New System.Drawing.Font("Arial", 8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.cmbDpt.Location = New System.Drawing.Point(430, 12)
        Me.cmbDpt.Name = "cmbDpt"
        Me.cmbDpt.Size = New System.Drawing.Size(221, 22)
        Me.cmbDpt.TabIndex = 64
        Me.cmbDpt.Visible = False
        '
        'dgProduct
        '
        Me.dgProduct.BackColor = System.Drawing.Color.AliceBlue
        Me.dgProduct.BackgroundColor = System.Drawing.Color.AliceBlue
        Me.dgProduct.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.dgProduct.CaptionVisible = False
        Me.dgProduct.DataMember = ""
        Me.dgProduct.HeaderBackColor = System.Drawing.Color.FromArgb(CType(CType(255, Byte), Integer), CType(CType(192, Byte), Integer), CType(CType(128, Byte), Integer))
        Me.dgProduct.HeaderForeColor = System.Drawing.SystemColors.ControlText
        Me.dgProduct.Location = New System.Drawing.Point(13, 66)
        Me.dgProduct.Name = "dgProduct"
        Me.dgProduct.ReadOnly = True
        Me.dgProduct.Size = New System.Drawing.Size(636, 276)
        Me.dgProduct.TabIndex = 66
        '
        'cmbCompany
        '
        Me.cmbCompany.BackColor = System.Drawing.Color.AliceBlue
        Me.cmbCompany.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList
        Me.cmbCompany.Location = New System.Drawing.Point(460, 40)
        Me.cmbCompany.Name = "cmbCompany"
        Me.cmbCompany.Size = New System.Drawing.Size(191, 26)
        Me.cmbCompany.TabIndex = 67
        Me.cmbCompany.Visible = False
        '
        'Label3
        '
        Me.Label3.AutoSize = True
        Me.Label3.BackColor = System.Drawing.Color.Transparent
        Me.Label3.ForeColor = System.Drawing.SystemColors.ActiveCaptionText
        Me.Label3.Location = New System.Drawing.Point(14, 8)
        Me.Label3.Name = "Label3"
        Me.Label3.Size = New System.Drawing.Size(99, 18)
        Me.Label3.TabIndex = 95
        Me.Label3.Text = "Account Group"
        '
        'cmbAccGroup
        '
        Me.cmbAccGroup.DisplayMember = "Text"
        Me.cmbAccGroup.DrawMode = System.Windows.Forms.DrawMode.OwnerDrawFixed
        Me.cmbAccGroup.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList
        Me.cmbAccGroup.ItemHeight = 19
        Me.cmbAccGroup.Location = New System.Drawing.Point(13, 30)
        Me.cmbAccGroup.Name = "cmbAccGroup"
        Me.cmbAccGroup.Size = New System.Drawing.Size(238, 25)
        Me.cmbAccGroup.TabIndex = 96
        '
        'GroupPanel1
        '
        Me.GroupPanel1.CanvasColor = System.Drawing.SystemColors.Control
        Me.GroupPanel1.ColorSchemeStyle = DevComponents.DotNetBar.eDotNetBarStyle.Office2007
        Me.GroupPanel1.Controls.Add(Me.cmdPrint)
        Me.GroupPanel1.Controls.Add(Me.cmdRefresh)
        Me.GroupPanel1.Controls.Add(Me.cmdExit)
        Me.GroupPanel1.Controls.Add(Me.cmdEdit)
        Me.GroupPanel1.Controls.Add(Me.dgProduct)
        Me.GroupPanel1.Controls.Add(Me.cmbAccGroup)
        Me.GroupPanel1.Controls.Add(Me.Label3)
        Me.GroupPanel1.Dock = System.Windows.Forms.DockStyle.Fill
        Me.GroupPanel1.Location = New System.Drawing.Point(0, 0)
        Me.GroupPanel1.Name = "GroupPanel1"
        Me.GroupPanel1.Size = New System.Drawing.Size(667, 439)
        '
        '
        '
        Me.GroupPanel1.Style.BackColor2SchemePart = DevComponents.DotNetBar.eColorSchemePart.PanelBackground2
        Me.GroupPanel1.Style.BackColorGradientAngle = 90
        Me.GroupPanel1.Style.BackColorSchemePart = DevComponents.DotNetBar.eColorSchemePart.PanelBackground
        Me.GroupPanel1.Style.BorderBottom = DevComponents.DotNetBar.eStyleBorderType.Solid
        Me.GroupPanel1.Style.BorderBottomWidth = 1
        Me.GroupPanel1.Style.BorderColorSchemePart = DevComponents.DotNetBar.eColorSchemePart.PanelBorder
        Me.GroupPanel1.Style.BorderLeft = DevComponents.DotNetBar.eStyleBorderType.Solid
        Me.GroupPanel1.Style.BorderLeftWidth = 1
        Me.GroupPanel1.Style.BorderRight = DevComponents.DotNetBar.eStyleBorderType.Solid
        Me.GroupPanel1.Style.BorderRightWidth = 1
        Me.GroupPanel1.Style.BorderTop = DevComponents.DotNetBar.eStyleBorderType.Solid
        Me.GroupPanel1.Style.BorderTopWidth = 1
        Me.GroupPanel1.Style.CornerDiameter = 4
        Me.GroupPanel1.Style.CornerType = DevComponents.DotNetBar.eCornerType.Rounded
        Me.GroupPanel1.Style.TextAlignment = DevComponents.DotNetBar.eStyleTextAlignment.Center
        Me.GroupPanel1.Style.TextColorSchemePart = DevComponents.DotNetBar.eColorSchemePart.PanelText
        Me.GroupPanel1.Style.TextLineAlignment = DevComponents.DotNetBar.eStyleTextAlignment.Near
        Me.GroupPanel1.TabIndex = 97
        Me.GroupPanel1.Text = "COA - Search"
        '
        'cmdPrint
        '
        Me.cmdPrint.AccessibleRole = System.Windows.Forms.AccessibleRole.PushButton
        Me.cmdPrint.Font = New System.Drawing.Font("Calibri", 11.25!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.cmdPrint.ForeColor = System.Drawing.Color.FromArgb(CType(CType(0, Byte), Integer), CType(CType(0, Byte), Integer), CType(CType(64, Byte), Integer))
        Me.cmdPrint.Location = New System.Drawing.Point(302, 358)
        Me.cmdPrint.Name = "cmdPrint"
        Me.cmdPrint.Size = New System.Drawing.Size(82, 26)
        Me.cmdPrint.TabIndex = 231
        Me.cmdPrint.Text = "Print"
        '
        'cmdRefresh
        '
        Me.cmdRefresh.AccessibleRole = System.Windows.Forms.AccessibleRole.PushButton
        Me.cmdRefresh.Font = New System.Drawing.Font("Calibri", 11.25!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.cmdRefresh.ForeColor = System.Drawing.Color.FromArgb(CType(CType(0, Byte), Integer), CType(CType(0, Byte), Integer), CType(CType(64, Byte), Integer))
        Me.cmdRefresh.Location = New System.Drawing.Point(478, 358)
        Me.cmdRefresh.Name = "cmdRefresh"
        Me.cmdRefresh.Size = New System.Drawing.Size(82, 26)
        Me.cmdRefresh.TabIndex = 230
        Me.cmdRefresh.Text = "Refresh"
        '
        'cmdExit
        '
        Me.cmdExit.AccessibleRole = System.Windows.Forms.AccessibleRole.PushButton
        Me.cmdExit.Font = New System.Drawing.Font("Calibri", 11.25!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.cmdExit.ForeColor = System.Drawing.Color.FromArgb(CType(CType(0, Byte), Integer), CType(CType(0, Byte), Integer), CType(CType(64, Byte), Integer))
        Me.cmdExit.Location = New System.Drawing.Point(566, 357)
        Me.cmdExit.Name = "cmdExit"
        Me.cmdExit.Size = New System.Drawing.Size(82, 27)
        Me.cmdExit.TabIndex = 229
        Me.cmdExit.Text = "Exit"
        '
        'cmdEdit
        '
        Me.cmdEdit.AccessibleRole = System.Windows.Forms.AccessibleRole.PushButton
        Me.cmdEdit.Font = New System.Drawing.Font("Calibri", 11.25!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.cmdEdit.ForeColor = System.Drawing.Color.FromArgb(CType(CType(0, Byte), Integer), CType(CType(0, Byte), Integer), CType(CType(64, Byte), Integer))
        Me.cmdEdit.Location = New System.Drawing.Point(390, 358)
        Me.cmdEdit.Name = "cmdEdit"
        Me.cmdEdit.Size = New System.Drawing.Size(82, 26)
        Me.cmdEdit.TabIndex = 228
        Me.cmdEdit.Text = "Edit"
        '
        'frmCOASearch
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(7, 19)
        Me.BackColor = System.Drawing.SystemColors.ActiveCaption
        Me.ClientSize = New System.Drawing.Size(667, 439)
        Me.ControlBox = False
        Me.Controls.Add(Me.GroupPanel1)
        Me.Controls.Add(Me.cmbCompany)
        Me.Controls.Add(Me.cmbDpt)
        Me.Font = New System.Drawing.Font("Calibri", 11.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.ForeColor = System.Drawing.SystemColors.ControlLightLight
        Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle
        Me.Location = New System.Drawing.Point(100, 70)
        Me.MaximizeBox = False
        Me.MinimizeBox = False
        Me.Name = "frmCOASearch"
        Me.ShowInTaskbar = False
        Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
        CType(Me.dgProduct, System.ComponentModel.ISupportInitialize).EndInit()
        Me.GroupPanel1.ResumeLayout(False)
        Me.GroupPanel1.PerformLayout()
        Me.ResumeLayout(False)

    End Sub

#End Region
    Private Sub ARcustomer_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim ARdata As New ARdataLogic
        Dim ds As DataSet
        ds = ARdata.GetAllCompany()
        cmbCompany.DataSource = ds.Tables(0)
        cmbCompany.ValueMember = "CompanyID"
        cmbCompany.DisplayMember = "CompanyName"
        cmbCompany.SelectedValue = CompanyID
        LoadGroupCombos(CompanyID)
        toPerformRefreshButtonClick()
        ''
    End Sub
    Private Sub LoadGroupCombos(ByVal CompanyCode As Integer)
        Dim GLdata As New GLdataLogic
        Dim ds, ds2 As DataSet

        ds = GLdata.GetAccountGroups()
        cmbAccGroup.DataSource = ds.Tables(0)
        cmbAccGroup.ValueMember = "GroupID"
        cmbAccGroup.DisplayMember = "GroupName"
        cmbAccGroup.SelectedValue = 0
        '
        ds2 = GLdata.GetCompanyDepartments(CompanyCode)
        cmbDpt.DataSource = ds2.Tables(0)
        cmbDpt.ValueMember = "AccountID"
        cmbDpt.DisplayMember = "AccountName"
        cmbDpt.SelectedValue = 0
        '
        GLdata = Nothing
    End Sub
    Sub toPerformRefreshButtonClick()
        Dim GLdata As New GLdataLogic
        dsAccounts = GLdata.GetAccountsByCompany(cmbCompany.SelectedValue, cmbAccGroup.SelectedValue, cmbDpt.SelectedValue)
        dgProduct.DataSource = dsAccounts.Tables(0)
        With dgProduct
            .TableStyles.Clear()
            .CaptionBackColor = System.Drawing.Color.SlateBlue
            .CaptionForeColor = System.Drawing.Color.LemonChiffon
            .AllowSorting = True
            .AlternatingBackColor = System.Drawing.Color.AliceBlue
            .ParentRowsBackColor = System.Drawing.Color.Lavender
            .ParentRowsForeColor = System.Drawing.Color.SlateBlue
            .HeaderBackColor = System.Drawing.Color.LemonChiffon
            .AllowNavigation = False
            .ParentRowsVisible = False
            .RowHeadersVisible = False
        End With
        Dim cm As CurrencyManager = BindingContext(dgProduct.DataSource, dgProduct.DataMember)
        Dim dv As DataView = cm.List
        dv.AllowNew = False
        dgformat(dsAccounts.Tables(0).Rows.Count)
        GLdata = Nothing
    End Sub
    Private Sub cmdRefresh_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdRefresh.Click
        Call toPerformRefreshButtonClick()
    End Sub
    Private Sub dgformat(ByVal RowCount As Integer)
        Dim grdTableStyle As New DataGridTableStyle
        With grdTableStyle
            .AlternatingBackColor = Color.AliceBlue
            .HeaderFont = New Font("Calibri", 9.0!, FontStyle.Bold)
            .MappingName = "ACCOUNT"
            .PreferredColumnWidth = 160
            .HeaderBackColor = Color.LightSlateGray
            .HeaderForeColor = Color.LightCyan
            .PreferredRowHeight = 15
            .RowHeadersVisible = False
            .RowHeaderWidth = 0
        End With
        Dim cs1 As DataGridColumnStyle
        cs1 = New DataGridTextBoxColumn
        cs1.Width = 0
        cs1.MappingName = "ACCOUNTID"
        cs1.HeaderText = "ID"
        cs1.NullText = ""
        cs1.ReadOnly = True
        grdTableStyle.GridColumnStyles.Add(cs1)
        '
        cs1 = New DataGridTextBoxColumn
        cs1.Width = 75
        cs1.MappingName = "ACCOUNTNUMBER"
        cs1.HeaderText = "NUMBER"
        cs1.NullText = ""
        cs1.ReadOnly = True
        grdTableStyle.GridColumnStyles.Add(cs1)
        '
        cs1 = New DataGridTextBoxColumn
        cs1.Width = 57
        cs1.MappingName = "ACCOUNTCENTER"
        cs1.HeaderText = "DPT"
        cs1.NullText = ""
        cs1.ReadOnly = True
        grdTableStyle.GridColumnStyles.Add(cs1)
        '
        cs1 = New DataGridTextBoxColumn
        cs1.Width = 260
        cs1.MappingName = "ACCOUNTNAME"
        cs1.HeaderText = "DESCRIPTION"
        cs1.NullText = ""
        cs1.ReadOnly = True
        grdTableStyle.GridColumnStyles.Add(cs1)
        '
        cs1 = New DataGridTextBoxColumn
        cs1.Width = 215
        cs1.MappingName = "GROUPNAME"
        cs1.HeaderText = "GROUP"
        cs1.NullText = ""
        cs1.ReadOnly = True
        grdTableStyle.GridColumnStyles.Add(cs1)
        '
        dgProduct.TableStyles.Add(grdTableStyle)
    End Sub

    Private Sub cmbCompany_Validating(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles cmbCompany.Validating
        LoadGroupCombos(cmbCompany.SelectedValue)
    End Sub

    Private Sub cmdExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdExit.Click
        Me.Hide()
    End Sub

    Private Sub cmdEdit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdEdit.Click
        Dim ApData As New APdataLogic
        If ApData.IsValidUserOption(UserID, CompanyID, 21) = True Then
            Dim CurrentRow As Integer = dgProduct.CurrentCell.RowNumber
            EditGlMain = dgProduct.Item(CurrentRow, 1)
            EditGlSub = dgProduct.Item(CurrentRow, 2)
            glcEdit = New frmCOAEdit
            glcEdit.ShowDialog()
        Else
            MsgBox("Access Denied ", MsgBoxStyle.Critical, "Inventory Manager")
        End If
    End Sub

    Private Sub dgProduct_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles dgProduct.MouseUp
        Dim pt As New Point(e.X, e.Y)
        Dim hti As DataGrid.HitTestInfo = dgProduct.HitTest(pt)
        If hti.Type = DataGrid.HitTestType.Cell Then
            dgProduct.CurrentCell = New DataGridCell(hti.Row, hti.Column)
            dgProduct.Select(hti.Row)
        End If
    End Sub

    Private Sub cmbCompany_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmbCompany.SelectedIndexChanged
        If IsNumeric(cmbCompany.SelectedValue) Then
            LoadGroupCombos(cmbCompany.SelectedValue)
        End If
    End Sub

    Private Sub cmdPrint_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdPrint.Click
        DetailedReport()
    End Sub
    Private Sub DetailedReport()
        Dim ds As DataSet = New DataSet("GLaccountsList")
        Dim table As DataTable = New DataTable("GLaccountsList")
        table.Columns.Add("AccountNumber")
        table.Columns.Add("AccountCenter")
        table.Columns.Add("AccountName")
        table.Columns.Add("AccountGroup")
        Dim mrow, drow As Integer
        Dim cm As CurrencyManager = BindingContext(dgProduct.DataSource, dgProduct.DataMember)
        Dim dv As DataView = cm.List
        dv.RowStateFilter = DataViewRowState.CurrentRows
        mrow = dv.Count
        'mrow = mrow - drow
        Dim ProdCode As String
        Dim ProdDesc As String
        Dim ProdQty As String

        Dim n As Integer
        For n = 0 To mrow - 1
            Dim nrow As DataRow = table.NewRow()
            nrow("AccountNumber") = dgProduct.Item(n, 1)
            nrow("AccountCenter") = dgProduct.Item(n, 2)
            nrow("AccountName") = dgProduct.Item(n, 3)
            nrow("AccountGroup") = dgProduct.Item(n, 4)
            table.Rows.Add(nrow)
        Next
        ds.Tables.Add(table)

        iPrint.Load()
        iPrint.SetDataSource(ds)

        iPrint.SetParameterValue("CompanyName", CompanyTitle)
        iPrint.SetParameterValue("ReportTitle", "Chart of Accounts")
        If PrntPrv Is Nothing Then
            PrntPrv = New PrintPreviewForm
            PrntPrv.CrRptView.ReportSource = iPrint
            PrntPrv.ShowDialog()
        End If
        iPrint.Close()
        'iprint.PrintOptions.PrinterName = InvoicePrinter
        'Try
        '    iprint.PrintToPrinter(1, True, 0, 0)
        'Catch ex As Exception
        '    MsgBox(ex.ToString)
        'End Try
    End Sub

    Private Sub cmbGroup1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmbAccGroup.SelectedIndexChanged
        If IsNumeric(cmbAccGroup.SelectedValue) Then
            toPerformRefreshButtonClick()
        End If
    End Sub

    
End Class
